$(function() {
	//启用拖拽
	Common.DragStart($(".setting_header")[0]);
	//关闭按钮
	$(".close").bind("click", function(event) {
		event.stopPropagation();		
		window.nativeWindow.close();
	});
	//最小化
	$(".min").bind("click", function() {
		event.stopPropagation();
		window.nativeWindow.minimize();
	});
	//左侧功能按钮
	$(".setting_left").find("li").bind("click", function(event) {
		event.stopPropagation();
		$(".setting_left").find("li").removeClass("li_enter");
		$(".setting_left").find("li").addClass("li_leave");
		$(this).removeClass("li_leave");
		$(this).addClass("li_enter");
		$(".setting_right").find("div[id]").hide();
		$("#" + $(this).attr("target")).show();
	});
	$(".setting_left").bind("click", function() {
		$(".setting_left").find("li").removeClass("li_enter");
		$(".setting_left").find("li").addClass("li_leave");
	});
	//出发第一个功能按钮
	$(".setting_left").find("li").eq(0).trigger("click");

	//取消
	$("#btnCancel").bind("click", function() {
		$(".close").trigger("click");
	});
	$("#wsurl").bind("keydown", function() {
		if(event.keyCode != 13)
			return;
		if(Const._isbusy)
			return;
		$("#btnConfirm").trigger("click");
	});
	//确定...........

	$("#btnConfirm").bind("click", function() {
		ShowLoading();

		var rembPwd = "";
		if($("#cbox_rembpwd")[0].checked == true) {
			rembPwd = 1;
		} else {
			rembPwd = 0;
		}
		var autoLogin = "";
		if($("#cbox_autologin")[0].checked == true) {
			autoLogin = 1;
		} else {
			autoLogin = 0;
		}
		var close = "";
		if($("#radio_min")[0].checked == true) {
			close = 0;
		} else {
			close = 1;
		}
		var playSound = "";
		if($("#radio_sound_open")[0].checked == true) {
			playSound = 1;
		} else {
			playSound = 0;
		}
		var pop = "";
		if($("#radio_pop_open")[0].checked == true) {
			pop = 1;
		} else {
			pop = 0;
		}
		var Config = Common.GetEmptyConfig();
		Config.WsURL = $("#wsurl").val();		
		Config.AutoLogin = autoLogin;
		Config.RembPwd = rembPwd;
		Config.Close = close;
		Config.PlaySound = playSound;
		Config.Pop = pop;
		Net.CheckNet(Config.WsURL, function() {
			Common.ShowTips("网络访问超时");
			HideLoading();
		}, function() {
			App.setConfig(Config);
			//重置更新时间
			App.UpdateCache("org", 0);
			//清空关注人
			App.clearCareUsers();
			$(".close").trigger("click");
			HideLoading();
		});
	});
	//初始化页面信息
	var configinfo = App.getConfig();
	if(configinfo != null) {
		$("#wsurl").val(configinfo.WsURL);
		//记住密码
		if(configinfo.RembPwd == 1) {
			$("#cbox_rembpwd")[0].checked = true;
			$("#tbox_pwd").val(configinfo.Password);
			$("#tbox_logincode").val(configinfo.LoginCode);
		}
		//自动登录
		if(configinfo.AutoLogin == 1) {
			$("#cbox_autologin")[0].checked = true;
		}
		//关闭模式   最小化到托盘，直接关闭
		if(configinfo.Close == 0) {
			$("#radio_min")[0].checked = true;
		} else {
			$("#radio_close")[0].checked = true;
		}
		//声音提醒
		if(configinfo.PlaySound == 1) {
			$("#radio_sound_open")[0].checked = true;
		} else {
			$("#radio_sound_close")[0].checked = true;
		}
		//气泡提醒
		if(configinfo.Pop == 1) {
			$("#radio_pop_open")[0].checked = true;
		} else {
			$("#radio_pop_close")[0].checked = true;
		}
	}
});
function ShowLoading() {
	$(".setting_loading").show();
	Const._isbusy = true;
}

function HideLoading() {
	$(".setting_loading").hide();
	Const._isbusy = false;
}